<template>
  <div class="app-container">
    <el-form ref="form" :model="blog" label-width="80px" size="mini">
      <el-form-item label="标题">
        <el-input v-model="blog.blogTitle" />
      </el-form-item>
      <el-form-item label="分类">
        <el-select v-model="blog.blogType" clearable filterable placeholder="请选择" style="width: 100%">
          <el-option
            v-for="type in typeList"
            :key="type.typeId"
            :label="type.typeName"
            :value="type.typeId"
          />
        </el-select></el-form-item>
      <el-form-item label="封面">
        <single-upload v-model="blog.blogImage"></single-upload>
      </el-form-item>
      <el-form-item label="内容">
        <tinymce v-model="blog.blogContent" />
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="blog.blogRemark" type="textarea" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="onSubmit">提交</el-button>
        <el-button size="mini" @click="closeAddDialog">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import SingleUpload from "@/components/upload/singleUpload"
import Tinymce from '@/components/Tinymce/index'
import blogApi from '@/api/blog'
import typeApi from '@/api/type'
  export default{

    components:{
      Tinymce,
      SingleUpload
    },

    data(){
      return{
        blog:{},
        typeList:null
      }
      
    },
    methods:{
      //获取所有博客类型接口
      getAllType(){
        typeApi.getTypeList()
        .then(res=>{
          this.typeList = res.data.typeList
          console.log("typeList",res.data.typeList)
        })
      },
      onSubmit(){
        blogApi.saveBlog(this.blog)
        .then(res=>{
          this.blog = {}
          this.$message.success(res.message)
          this.$emit("onSubmit")
          this.$emit('closeAddDialog')
          
        }).catch(res=>{
          this.$message.error(res.message);
          })
      },
      closeAddDialog(){
        this.$emit('closeAddDialog')
      }
    },
    created(){
      this.getAllType()
    }



  }

</script>
<style>
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
